import request from '@/utils/request'
import qs from 'qs'

export function login(data, deviceId) {
  return request({
    url: 'auth/auth/form',
    method: 'post',
    headers: { deviceId: deviceId, 'Content-Type': 'application/x-www-form-urlencoded' },
    data: qs.stringify({
      grant_type: 'password',
      username: data.username,
      password: data.password,
      imageCode: data.imageCode
    })
  })
}

export function getCode(deviceId) {
  return request({
    url: 'auth/auth/code/image',
    method: 'get',
    headers: { deviceId: deviceId }
  })
}

export function getInfo(token) {
  return request({
    url: 'admin/user/info',
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: 'auth/token/logout',
    method: 'delete'
  })
}
